package demo;
// 随机数保底机制  好玩
import java.util.Random;
import java.util.Scanner;

public class Test24 {
    public static void main(String[] args) {

        int count=0;

        //生成随机数
        Random r = new Random();
        int number = r.nextInt(100) +1;
        System.out.println(number);
        //猜这个数
        Scanner sc = new Scanner(System.in);

        while (true) {
            System.out.print("请输入要猜数: ");
            int guessNumber = sc.nextInt();

            count++;
            if (count == 3){
                System.out.println("猜中了");
                break;
            }

            if (guessNumber > number) {
                System.out.println("猜大了");
            } else if (guessNumber < number) {
                System.out.println("猜小了");
            } else {
                System.out.println("恭喜你，猜中了");
                break;
            }

        }

    }
}

